package com.gusha.config;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import com.gusha.utils.StringToDateConverter;

@Configuration
public class WebConfigBeans {

	@Autowired
	RequestMappingHandlerAdapter requestMappingHandlerAdapter;

	@PostConstruct
	public void initEditableValidation() {
		ConfigurableWebBindingInitializer configurableWebBindingInitializer = (ConfigurableWebBindingInitializer) requestMappingHandlerAdapter
				.getWebBindingInitializer();
		if (configurableWebBindingInitializer.getConversionService() != null) {
			GenericConversionService service = (GenericConversionService) configurableWebBindingInitializer.getConversionService();
			service.addConverter(new StringToDateConverter());
		}
	}
}
